package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bussiness.domain.SysBusinessCheckList;
import com.ruoyi.bussiness.domain.SysListRelatedResource;
import com.ruoyi.bussiness.service.ISysBusinessCheckListService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 清单Controller
 * 
 * @author ruoyi
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/system/list")
public class SysBusinessCheckListController extends BaseController
{
    @Autowired
    private ISysBusinessCheckListService sysBusinessCheckListService;

    /**
     * 查询清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBusinessCheckList sysBusinessCheckList)
    {
        startPage();
        List<SysBusinessCheckList> list = sysBusinessCheckListService.selectSysBusinessCheckListList(sysBusinessCheckList);
        return getDataTable(list);
    }

    /**
     * 导出清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:export')")
    @Log(title = "清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBusinessCheckList sysBusinessCheckList)
    {
        List<SysBusinessCheckList> list = sysBusinessCheckListService.selectSysBusinessCheckListList(sysBusinessCheckList);
        ExcelUtil<SysBusinessCheckList> util = new ExcelUtil<SysBusinessCheckList>(SysBusinessCheckList.class);
        util.exportExcel(response, list, "清单数据");
    }

    /**
     * 获取清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:query')")
    @GetMapping(value = "/{checkListId}")
    public AjaxResult getInfo(@PathVariable("checkListId") Long checkListId)
    {
        return success(sysBusinessCheckListService.selectSysBusinessCheckListByCheckListId(checkListId));
    }

    /**
     * 新增清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:add')")
    @Log(title = "清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBusinessCheckList sysBusinessCheckList)
    {
        return toAjax(sysBusinessCheckListService.insertSysBusinessCheckList(sysBusinessCheckList));
    }

    /**
     * 修改清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBusinessCheckList sysBusinessCheckList)
    {
        return toAjax(sysBusinessCheckListService.updateSysBusinessCheckList(sysBusinessCheckList));
    }

    /**
     * 删除清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:remove')")
    @Log(title = "清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{checkListIds}")
    public AjaxResult remove(@PathVariable Long[] checkListIds)
    {
        return toAjax(sysBusinessCheckListService.deleteSysBusinessCheckListByCheckListIds(checkListIds));
    }

    /**
     * 删除清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "清单", businessType = BusinessType.UPDATE)
    @PutMapping("/withdraw/{checkListIds}")
    public AjaxResult withdraw(@PathVariable Long[] checkListIds)
    {
        if(StringUtils.isEmpty(checkListIds)){
            return error("请选择要撤回的清单数据");
        }
        return toAjax(sysBusinessCheckListService.withdrawSysBusinessCheckListByCheckListIds(checkListIds));
    }

    /**
     * 上移下移清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "清单", businessType = BusinessType.UPDATE)
    @PutMapping("/moveUpOrDown")
    public AjaxResult moveUpOrDown(@RequestBody SysBusinessCheckList entity)
    {
        return sysBusinessCheckListService.moveUpOrDown(entity);
    }

    /**
     * 置顶 置底清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "清单", businessType = BusinessType.UPDATE)
    @PutMapping("/pinToTopOrEnd")
    public AjaxResult pinToTopOrEnd(@RequestBody SysBusinessCheckList entity)
    {
        return sysBusinessCheckListService.pinToTopOrEnd(entity);
    }


    /**
     * 置顶 置底清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "清单", businessType = BusinessType.UPDATE)
    @GetMapping("/getRelateReadList")
    public AjaxResult getRelateReadList(SysBusinessCheckList entity)
    {
        return sysBusinessCheckListService.getRelateReadList(entity);
    }

    /**
     *
     */
    @Log(title = "清单", businessType = BusinessType.UPDATE)
    @GetMapping("/getRelateResourceList")
    public AjaxResult getRelateResourceList(SysBusinessCheckList entity)
    {
        return sysBusinessCheckListService.getRelateResourceList(entity);
    }

    @PreAuthorize("@ss.hasPermi('system:list:query')")
    @GetMapping(value = "/getBridgeNum")
    public AjaxResult getBridgeNum(@RequestParam("bridgeType") String bridgeType)
    {
        return AjaxResult.success("获取编号成功",sysBusinessCheckListService.getBridgeNum(bridgeType));
    }

    /**
     * @Author shining
     * @Description 获取资源信息
     * @Date 15:33 2024/6/9
     * @Param [dynamicIds]
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @GetMapping("/getResourceByType")
    public TableDataInfo getResourceByType(SysListRelatedResource sysListRelatedResource)
    {
        startPage();
        List<SysListRelatedResource> list = sysBusinessCheckListService.getRelateResourceListByType(sysListRelatedResource);
        return getDataTable(list);
    }
}
